import type { RouteRecordRaw } from 'vue-router'

const loadComponent = (name: string) => {
  return () => import(/* webpackChunkName: "pcf" */ `@/views/pcf/${name}/index.vue`)
}
const loadWorkbenchComponent = (name: string) => {
  return () => import(/* webpackChunkName: "workbench" */ `@/views/${name}/index.vue`)
}

export const routes: Array<RouteRecordRaw> = [
  {
    path: '/myModel/modelList',
    component: loadComponent('myModel'),
    name: 'MyModelList',
    meta: {
      title: '整车碳足迹模型',
      // keep alive
      keepAlive: true,
      activeMenu: '/pcf'
    }
  },
  {
    path: '/myModel/partsModel',
    component: loadComponent('myModel'),
    name: 'PartsModel',
    meta: {
      title: '零部件组件模型',
      // keep alive
      keepAlive: true,
      activeMenu: '/pcf'
    }
  },
  {
    path: 'myModel/addModel',
    component: loadComponent('myModel/addModel'),
    name: 'AddModel',
    meta: {
      title: '创建模型',
      selectKeysPath: '/myModel/modelList',
      bgColor: '#EDF2F5',
      breadcrumb: [
        {
          name: '碳足迹模型',
          path: false
        },
        {
          name: '创建模型',
          path: false
        }
      ],
      breadcrumbGenerator: (to: any, from?: any) => {
        console.log(to, from, 'to, from')
        if (from.name === 'MyModelList') {
          to.meta.breadcrumb[0].name = '整车碳足迹模型'
          to.meta.breadcrumb[0].path = '/myModel/modelList'
        } else if (from.name === 'PartsModel') {
          to.meta.breadcrumb[0].name = '零部件组件模型'
          to.meta.breadcrumb[0].path = '/myModel/partsModel'
        }
      },
      activeMenu: '/pcf',
      keepAliveParentName: ['MyModelList', 'PartsModel']
    }
  },
  {
    path: 'myModel/modelDetail',
    component: loadComponent('myModel/addModel'),
    name: 'ModelDetail',
    meta: {
      title: '模型详情',
      selectKeysPath: '/myModel/modelList',
      bgColor: '#EDF2F5',
      breadcrumb: [
        {
          name: '碳足迹模型',
          path: false
        },
        {
          name: '模型详情',
          path: false
        }
      ],
      breadcrumbGenerator: (to: any, from?: any) => {
        console.log(to, from, 'to, from')
        if (from.query.type === 'finishedAutomobileModel') {
          to.meta.breadcrumb[0].name = '整车碳足迹模型'
          to.meta.breadcrumb[0].path = '/myModel/modelList'
        } else if (from.query.type === 'partsModel') {
          to.meta.breadcrumb[0].name = '零部件组件模型'
          to.meta.breadcrumb[0].path = '/myModel/partsModel'
        }
      },
      keepAliveParentName: ['MyModelList', 'PartsModel'],
      activeMenu: '/pcf'
    }
  },
  {
    path: 'myModel/modelFill/:modelNo',
    component: loadComponent(`myModel/modelDetail`),
    name: 'ModelFill',
    meta: {
      title: '模型详情',
      selectKeysPath: '/myModel/modelList',
      bgColor: '#EDF2F5',
      breadcrumb: [
        {
          name: '碳足迹模型',
          path: false
        },
        {
          name: '模型详情',
          path: false
        }
      ],
      breadcrumbGenerator: (to: any, from?: any) => {
        console.log(to, from, 'to, from')
        if (from.name === 'MyModelList') {
          to.meta.breadcrumb[0].name = '整车碳足迹模型'
          to.meta.breadcrumb[0].path = '/myModel/modelList'
        } else if (from.name === 'PartsModel') {
          to.meta.breadcrumb[0].name = '零部件组件模型'
          to.meta.breadcrumb[0].path = '/myModel/partsModel'
        }
      },
      keepAlive: true,
      keepAliveParentName: ['MyModelList', 'PartsModel'],
      activeMenu: '/pcf'
    }
  },
  /**
   * dqr
   */
  {
    path: 'myModel/dqr/:modelNo',
    component: loadComponent('myModel/dqr'),
    name: 'DQR',
    meta: {
      title: '数据质量评价',
      selectKeysPath: '/myModel/modelList',
      keepAlive: true,
      bgColor: '#F3F7FB',
      breadcrumb: [
        {
          name: '碳足迹模型',
          path: false
        },
        {
          name: '模型详情',
          // path: '/myModel/modelFill/:dqrModelNo?step=3'
          path: false
        },
        {
          name: '数据质量评价',
          path: false
        }
      ],
      breadcrumbGenerator: (to: any, from?: any) => {
        console.log(to, from, 'to, from')
        if (from.query.type === 'finishedAutomobileModel') {
          to.meta.breadcrumb[0].name = '整车碳足迹模型'
          to.meta.breadcrumb[0].path = '/myModel/modelList'
          to.meta.breadcrumb[1].path =
            '/myModel/modelFill/:dqrModelNo?step=3&type=finishedAutomobileModel'
        } else if (from.query.type === 'partsModel') {
          to.meta.breadcrumb[0].name = '零部件组件模型'
          to.meta.breadcrumb[0].path = '/myModel/partsModel'
          to.meta.breadcrumb[1].path = '/myModel/modelFill/:dqrModelNo?step=3&type=partsModel'
        }
      },
      keepAliveParentName: ['MyModelList', 'PartsModel'],
      activeMenu: '/pcf'
    }
  },
  /**
   * 供应商数据集
   */
  {
    path: '/supplierData',
    component: loadComponent('supplierData'),
    name: 'SupplierData',
    meta: {
      title: '供应商数据集',
      keepAlive: true,
      activeMenu: '/pcf'
    }
  },
  {
    path: '/supplierData/detail',
    component: loadWorkbenchComponent('todo/detail'),
    name: 'SupplierDataTodoListDetail',
    meta: {
      title: '详情',
      bgColor: '#EDF2F5',
      keepAliveParentName: ['SupplierData'],
      breadcrumb: [
        {
          name: '供应商数据集',
          path: '/supplierData'
        },
        {
          name: '详情',
          path: false
        }
      ],
      activeMenu: '/pcf'
    }
  },
  /**
   * 碳足迹报告
   */
  {
    path: '/lcaReport',
    component: loadComponent('lcaReport'),
    name: 'LcaReport',
    meta: {
      title: '碳足迹报告',
      keepAlive: true,
      activeMenu: '/pcf'
    }
  }
  // {
  //   path: '/pcfForm/emissionComparison',
  //   component: loadComponent('pcfForm/emissionComparison'),
  //   name: 'FootprintEmissionComparison',
  //   meta: {
  //     title: '碳排放对比分析',
  //     bgColor: '#F3F7FB',
  //     activeMenu: '/pcf'
  //   }
  // },
  // {
  //   path: '/pcfForm/emissionDistribution',
  //   component: loadComponent('pcfForm/emissionDistribution'),
  //   name: 'FootprintemissionDistribution',
  //   meta: {
  //     title: '碳排放分布分析',
  //     bgColor: '#F3F7FB',
  //     activeMenu: '/pcf'
  //   }
  // }
]

export default routes
